import { alovaInstance } from './apiClient'
import type { Task, TaskCreatePayload, TaskUpdatePayload, TaskLog } from '../types/task'

// 创建任务
export const createTask = (data: TaskCreatePayload) => {
  return alovaInstance.Post('/tasks', data)
}

// 获取任务列表
export const getTasks = (params?: {
  group_id?: number
  status?: number
  is_important?: boolean
  is_my_day?: boolean
  page?: number
  page_size?: number
}) => {
  return alovaInstance.Get('/tasks', {
    params
  })
}

// 获取"我的一天"任务列表
export const getMyDayTasks = () => {
  return alovaInstance.Get('/tasks/my-day')
}

// 获取任务详情
export const getTaskDetail = (taskId: number) => {
  return alovaInstance.Get(`/tasks/${taskId}`)
}

// 更新任务
export const updateTask = (taskId: number, data: TaskUpdatePayload) => {
  return alovaInstance.Put(`/tasks/${taskId}`, data)
}

// 删除任务
export const deleteTask = (taskId: number) => {
  return alovaInstance.Delete(`/tasks/${taskId}`)
}

// 更新任务分组
export const updateTaskGroup = (taskId: number, data: { group_id: number }) => {
  return alovaInstance.Put(`/tasks/${taskId}/group`, data)
}

// 添加任务日志
export const addTaskLog = (taskId: number, data: { content: string }) => {
  return alovaInstance.Post(`/tasks/${taskId}/logs`, data)
}

// 获取任务日志列表
export const getTaskLogs = (taskId: number) => {
  return alovaInstance.Get(`/tasks/${taskId}/logs`)
}